package com.example.demo.IO;
import com.alibaba.fastjson.JSONObject;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/**
* @description: TODO Zip压缩
* @author 杨镇宇
* @date 2022/3/20 10:44
* @version 1.0
*/

public class Zip {
    public static void main(String[] args) throws IOException {
        String zipFileName = "D:\\work\\demo\\student.zip";
        String fileName = "D:\\work\\demo\\student.txt";
        File file = new File(fileName);
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
        out.putNextEntry(new ZipEntry("test.txt"));
        FileInputStream in = new FileInputStream(file);
        int tmp;
        while((tmp = in.read()) != -1) {
            out.write(tmp);
        }
        in.close();
        out.close();


    }
}
